package com.oocl.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.oocl.dao.FoodsDao;
import com.oocl.dao.base.BaseJPADaoUtil;
import com.oocl.entity.Foods;

@Repository("foodsDao")
public class FoodsDaoImpl extends BaseJPADaoUtil implements FoodsDao {

	

	/*
	 * @Method: findsFoodsByFname
	 * @function: load food by food name
	 * @param String fname
	 * @author wendy
	 * @date 2017-08-12
	 */
	
	public List<Foods> findFoodsByFname(String fname) {
		// TODO Auto-generated method stub
		System.out.println(fname);
		String jpql="select f from Foods f left join fetch f.merchant fm where f.fname=:fname";
		List<Foods> flist=new ArrayList<Foods>();
		flist=entityManager.createQuery(jpql,Foods.class).setParameter("fname", fname).getResultList();
		System.out.println(flist.size());
		return flist;
	}


	/*
	 * @Method: findsFoodsByIcnum
	 * @function: load food by merchant IC number
	 * @param String icnum
	 * @author wendy
	 * @date 2017-08-12
	 */
	
	public List<Foods> findFoodsByIcnum(String icnum) {
		// TODO Auto-generated method stub
		String jpql="select f from Foods f left join fetch f.merchant fm where fm.icnum=:icnum";
		List<Foods> flist=new ArrayList<Foods>();
		flist=entityManager.createQuery(jpql).setParameter("icnum", icnum).getResultList();
		return flist;
	}

	/*
	 * @Method: findsFoodsByFname
	 * @function: load food by food type
	 * @param String type
	 * @author wendy
	 * @date 2017-08-12
	 */
	
	public List<Foods> findFoodsByType(String type) {
		// TODO Auto-generated method stub
		String jpql="select f from Foods f left join fetch f.merchant fm where f.ftype=:ftype";
		List<Foods> flist=new ArrayList<Foods>();
		flist=entityManager.createQuery(jpql,Foods.class).setParameter("ftype", type).getResultList();
				
		return flist;
	}

	/*
	 * @Method: findsFoodsByFname
	 * @function: load food by merchant IC number and food type
	 * @param String icnum,String type
	 * @author wendy
	 * @date 2017-08-12
	 */
	
	public List<Foods> findFoodsByIcType(String icnum, String type) {
		// TODO Auto-generated method stub
		String jpql="select f from Foods f left join fetch f.merchant fm  where f.ftype=:ftype";
		List<Foods> flist=new ArrayList<Foods>();
		flist=entityManager.createQuery(jpql,Foods.class)
				.setParameter("ftype", type)
				.getResultList();
		return flist;
	}

}
